﻿using Battle.Engine.InputData;
using System;
using System.Collections.Generic;
using UnityEngine;
using Dict.Blo;
using Dict.DataModel;

namespace UI
{
    /// <summary>
    /// 战斗阵容队形
    /// </summary>
    public class UIHeroFormation
    {
        //阵容位置
        public int campPos { get; private set; }
        //战场位置
        public int battlePos { get; set; }
        //出战武者
        public UIHero hero;
        //阵型装备
        public UIEquipment[] equipments = new UIEquipment[4];
        //阵型首饰
        public UITreasure[] treasures = new UITreasure[2];
        //阵型宠物
        public UIPet pet;

        /// <summary>
        /// 缘分
        /// </summary>
        public List<UIHeroLuck> lucks = new List<UIHeroLuck>();

        //总体属性
        private BaseAttributeData currentAttribute;
        private double fightPower;
        #region 辅助
        public UIInstPlayerData simplePlayer;
        /// <summary>
        /// 主角
        /// </summary>
        public bool isUserHero
        {
            get
            {
                if (hero == null)
                {
                    return false;
                }
                return hero.IsUserHero;
            }
        }

        /// <summary>
        /// 英雄名称
        /// </summary>
        public string heroName
        {
            get
            {
                if (hero == null)
                {
                    return "";
                }
                return hero.heroName;
            }
        }

        #region 模块开放信息
        /// <summary>
        /// 解锁等级
        /// </summary>
        //private Dict.DataModel.TableModule unlockedModule;
        //private Dict.Enum.TableModuleEnum moduleEnumId;
        public bool IsUnlocked
        {
            get
            {
                return StaticData.playerData.level >= this.UnlockLevel;
            }
        }

        /// <summary>
        /// 模块开放信息
        /// </summary>
        public int UnlockLevel
        {
            get
            {
                switch (this.campPos)
                {
                    case 1:
                        return Dict.DictDataManager.Instance.tableGameConfigureDao.currentData.array_pos1;
                    case 2:
                        return Dict.DictDataManager.Instance.tableGameConfigureDao.currentData.array_pos2;
                    case 3:
                        return Dict.DictDataManager.Instance.tableGameConfigureDao.currentData.array_pos3;
                    case 4:
                        return Dict.DictDataManager.Instance.tableGameConfigureDao.currentData.array_pos4;
                }
                return 0;
            }
        }
        #endregion

        #region 套装
        /// <summary>
        /// 套装数量，ID,NUM
        /// </summary>
        public Dictionary<string, int> activeOutfitEquips = new Dictionary<string, int>();
        //套装属性
        private BaseAttributeData currentOutfitAttribute;
        #endregion
        #region 队友天赋加成
        public BaseAttributeData friendAddAtribute;
        public BaseAttributeData friendAddPercentAtribute;
        #endregion  队友天赋加成

        #region 强化大师
        //装备强化大师等级
        public int equipStrenthMasterLev { get { if (equipStrenthMasterLevData != null) { return equipStrenthMasterLevData.level; } else { return 0; } } }
        //装备精炼大师等级
        public int equipRefineMasterLev { get { if (equipRefineMasterLevData != null) { return equipRefineMasterLevData.level; } else { return 0; } } }
        //宝物强化大师等级
        public int treaStrenthMaterLev { get { if (treaStrenthMasterLevData != null) { return treaStrenthMasterLevData.level; } else { return 0; } } }
        //宝物精炼大师等级
        public int treaRefineMasterLev { get { if (treaRefineMasterLevData != null) { return treaRefineMasterLevData.level; } else { return 0; } } }
        //伙伴祝福
        public int partnerMasterLev { get { if (partnerMasterLevData != null) { return partnerMasterLevData.level; } else { return 0; } } }
        public int GetMasterLev(MasterType mt)
        {
            switch (mt)
            {
                case MasterType.Equip_Strengh:
                    return equipStrenthMasterLev;
                case MasterType.Equip_Refine:
                    return equipRefineMasterLev;
                case MasterType.Acc_Strenth:
                    return treaStrenthMaterLev;
                case MasterType.Acc_Refine:
                    return treaRefineMasterLev;
                default:
                    return equipStrenthMasterLev;
            }

        }

        public Dict.DataModel.TableStrengthenMaster equipStrenthMasterLevData { get; private set; }
        public Dict.DataModel.TableStrengthenMaster equipRefineMasterLevData { get; private set; }
        public Dict.DataModel.TableStrengthenMaster treaStrenthMasterLevData { get; private set; }
        public Dict.DataModel.TableStrengthenMaster treaRefineMasterLevData { get; private set; }
        public Dict.DataModel.TableStrengthenMaster partnerMasterLevData { get; private set; }
        //强化大师属性
        public BaseAttributeData currentMasterAttribute;
        #endregion

        #region 称号属性
        public BaseAttributeData currentTitleAttribute;

        #endregion

        #endregion


        public UIHeroFormation()
        {

        }

        public UIHeroFormation(int campPos, int battlePos, UIInstPlayerData simplePlayer)
        {
            this.campPos = campPos;
            this.battlePos = battlePos;
            //this.moduleEnumId = modelId;
            //this.unlockedModule = Dict.DictDataManager.Instance.tableModuleDao.GetById((int)this.moduleEnumId);
            this.simplePlayer = simplePlayer;
            this.currentMasterAttribute = new BaseAttributeData(0);
            this.currentOutfitAttribute = new BaseAttributeData(0);
            this.currentAttribute = new BaseAttributeData(0);
            this.currentTitleAttribute = new BaseAttributeData(0);
        }
        public void InitData(UIHero data)
        {
            //todo
            //机器人
        }

        /// <summary>
        /// 主英雄品质升级
        /// </summary>
        /// <param name="newHero"></param>
        public void MainHeroAdvance(UIHero newHero)
        {
            hero = newHero;
            hero.owner = this;
            RefreshLuckData();
        }

        public void InitData(ProtoBuf.Message.FormationItem data, bool isChange, bool recalculate)
        {
            this.campPos = data.formatPos;
            this.battlePos = data.battlePos;
            var tmpHero = hero;
            if (hero != null)
            {
                hero.owner = null;
            }
            var tempPet = pet;
            if(pet!=null)
            {
                pet.owner = null;
            }
            for (int i = 0; i < equipments.Length; i++)
            {
                if (equipments[i] != null)
                    equipments[i] = null;
            }
            for (int i = 0; i < treasures.Length; i++)
            {
                if (treasures[i] != null)
                    treasures[i] = null;
            }

            
            foreach (var innerData in data.things)
            {
                if (innerData.pos == Dict.Config.TableConst.BattleCampHeroPos)
                {
                    hero = simplePlayer.GetUIHero(innerData.guid);
                    hero.owner = this;
                    if (tmpHero != null)
                    {
                        ManagerController.Instance.formationResourceCache.ReplaceHero(hero.heroId, tmpHero.heroId);
                    }
                    else
                    {
                        ManagerController.Instance.formationResourceCache.LoadHero(hero.heroId);
                    }

                }
                else  if(innerData.pos == Dict.Config.TableConst.BattleCampPetPos)
                {
                    pet = simplePlayer.GetUIPet(innerData.guid);
                    pet.owner = this;

                }
                else if (innerData.pos == Dict.Config.TableConst.BattleCampEquipPos0
                   || innerData.pos == Dict.Config.TableConst.BattleCampEquipPos1
                   || innerData.pos == Dict.Config.TableConst.BattleCampEquipPos2
                   || innerData.pos == Dict.Config.TableConst.BattleCampEquipPos3)
                {
                    equipments[innerData.pos - 1] = simplePlayer.GetUIEquipment(innerData.guid);
                    equipments[innerData.pos - 1].owner = this;
                    equipments[innerData.pos - 1].lastHeroId = hero.heroId;
                }
                else if (innerData.pos == Dict.Config.TableConst.BattleCampTreasurePos0
                    || innerData.pos == Dict.Config.TableConst.BattleCampTreasurePos1)
                {
                    treasures[innerData.pos - 5] = simplePlayer.GetUITreasure(innerData.guid);
                    treasures[innerData.pos - 5].owner = this;
                }
                else
                {
                    Debug.LogError(" battle camp pos error:" + innerData.pos);
                }
                //Debug.Log("guid:" + innerData.guid + " id:" + innerData.id);
            }

            RefreshLuckData();

            UpdateEquipOutfit();
            if (recalculate)
            {
                ResetAttribute(simplePlayer.friendBuffers);
            }
            if (isChange && campPos == 1)
            {
                ProtoBuf.Message.CSRefreshMovePlayerInfo csmpi = new ProtoBuf.Message.CSRefreshMovePlayerInfo();
                NetAPI.SendSocket(ProtoBuf.Message.OpDefine.CSRefreshMovePlayerInfo, csmpi);
            }
        }

        void RefreshLuckData()
        {
            //缘分数据
            List<TableYuan> luckDatas = Dict.DictDataManager.Instance.tableYuanDao.GetByOneIndex(this.hero.heroId);
            lucks.Clear();
            foreach (var luckData in luckDatas)
            {
                lucks.Add(new UIHeroLuck(luckData, this.hero));
            }
        }


        /// <summary>
        /// 其他玩家阵容
        /// </summary>
        public void InitData(ProtoBuf.Message.FormationItemSimpleInfo data)
        {
            this.campPos = data.formatPos;
            currentAttribute = new BaseAttributeData(data.warInfo.baseProp);
            hero = new UIHero(data.warInfo.heroId);
            hero.InitData(data.warInfo);

            for (int i = 0; i < data.equipInfoList.Count; i++)
            {
                UIEquipment equip = new UIEquipment(data.equipInfoList[i], data.warInfo.heroId);
                equipments[equip.equipData.type - 1] = equip;
            }

            for (int i = 0; i < data.treaInfoList.Count; i++)
            {
                UITreasure treasure = new UITreasure(data.treaInfoList[i]);
                treasures[1 - treasure.treasureData.type] = treasure;
            }

            //缘分数据
            List<TableYuan> luckDatas = Dict.DictDataManager.Instance.tableYuanDao.GetByOneIndex(this.hero.heroId);
            lucks.Clear();
            foreach (var luckData in luckDatas)
            {
                lucks.Add(new UIHeroLuck(luckData, this.hero));
            }
        }

        /// <summary>
        /// 刷新阵容属性
        /// </summary>
        public void ResetAttribute(List<FriendBuffer> buffers)
        {
            this.currentAttribute.Reset();
            //更新强化大师信息
            UpdateStrenthMaster();
            UpdateTitleAttribute();
            CalculateFriendAttribute(buffers);
            BaseAttributeData per = new BaseAttributeData(0);
            if (hero != null)
            {
                this.currentAttribute.AddProp(hero.CurrentAttribute);
                per.AddProp(hero.CurrentPercentAttribute);
            }
            foreach (var equip in equipments)
            {
                if (equip != null)
                {
                    this.currentAttribute.AddProp(equip.CurrentAttribute);
                }
            }
            foreach (var trea in treasures)
            {
                if (trea != null)
                {
                    this.currentAttribute.AddProp(trea.CurrentAttribute);
                    per.AddProp(trea.PercentAttribute);
                }
            }

            //UpdateLuck();
            foreach (var ul in lucks)
            {
                if (ul.IsActived)
                {
                    per.AddProp(AttributeQueue.Attack, ul.luckData.peratt * CommonMethod.tableAttributeConvert);
                    per.AddProp(AttributeQueue.Hp, ul.luckData.perhp * CommonMethod.tableAttributeConvert);
                    per.AddProp(AttributeQueue.MagicDefend, ul.luckData.perdef * CommonMethod.tableAttributeConvert);
                    per.AddProp(AttributeQueue.PhyDefend, ul.luckData.perdef * CommonMethod.tableAttributeConvert);
                }
            }

            this.currentAttribute.AddProp(currentOutfitAttribute);
            this.currentAttribute.AddProp(currentMasterAttribute);
            this.currentAttribute.AddProp(currentTitleAttribute);
            this.currentAttribute.AddProp(friendAddAtribute);
            this.currentAttribute.AddProp(StaticData.playerData.worldSeed.attributeData);
            //公会建筑百分比加成
            per.AddProp(StaticData.unionAttributePer);
            //祈祷
            per.AddProp(StaticData.unionChurchAttributePer);
            per.AddProp(friendAddPercentAtribute);
            //属性百分百
            this.currentAttribute.Multiply(per.AddProp(1));


            //公会建筑常量加成
            currentAttribute.AddProp(StaticData.unionAttributeConst);

            //加装备的宝石属性
            foreach (var equip in equipments)
            {
                if (equip != null)
                {
                    this.currentAttribute.AddProp(equip.CurrentGemsAttribute);
                }
            }


            this.fightPower = 0.1 *
            (currentAttribute.GetProp(AttributeQueue.Attack) * Dict.DictDataManager.Instance.tableGameConfigureDao.currentData.fightpower_att_factor
            + currentAttribute.GetProp(AttributeQueue.Hp) * Dict.DictDataManager.Instance.tableGameConfigureDao.currentData.fightpower_hp_factor
            + currentAttribute.GetProp(AttributeQueue.PhyDefend) * Dict.DictDataManager.Instance.tableGameConfigureDao.currentData.fightpower_pdef_factor
            + currentAttribute.GetProp(AttributeQueue.MagicDefend) * Dict.DictDataManager.Instance.tableGameConfigureDao.currentData.fightpower_mdef_factor) *
            (CommonMethod.tableAttributeConvert_anti
            + currentAttribute.GetProp(AttributeQueue.cri)
            + currentAttribute.GetProp(AttributeQueue.criFactor)
            + currentAttribute.GetProp(AttributeQueue.antiCri)
            + currentAttribute.GetProp(AttributeQueue.hit)
            + currentAttribute.GetProp(AttributeQueue.dodge)
            + currentAttribute.GetProp(AttributeQueue.damageAdd)
            + currentAttribute.GetProp(AttributeQueue.damageReduce)
            - hero.GetDefaultPerProp()
            ) * CommonMethod.tableAttributeConvert;




#if UNITY_EDITOR
            //UnityEngine.Debug.LogWarning(heroName + " " + currentAttribute.ToString());
#endif
        }

        private void CalculateFriendAttribute(List<FriendBuffer> buffers)
        {
            friendAddAtribute = new BaseAttributeData();
            friendAddPercentAtribute = new BaseAttributeData();
            for (int i = 0; i < buffers.Count; ++i)
            {
                FriendBuffer tb = buffers[i];
                if (BuffFit(tb))
                {
                    UITalent.GetBufferAddProp(friendAddAtribute, friendAddPercentAtribute, tb.data);
                }
            }
        }

        private string spaceCondition = "type:space,src1:2,op:";
        private bool BuffFit(FriendBuffer tb)
        {
            if (string.IsNullOrEmpty(tb.selectStrategy))
            {
                return true;
            }
            else
            {
                if (tb.selectStrategy.StartsWith(spaceCondition))
                {

                    Battle.Engine.ConditionOP op = (Battle.Engine.ConditionOP)(tb.selectStrategy[spaceCondition.Length] - '0');
                    int sc = tb.selectStrategy[tb.selectStrategy.Length - 1] - '0';
                    switch (op)
                    {
                        case Battle.Engine.ConditionOP.More:
                            return hero.heroData.space > sc;
                        case Battle.Engine.ConditionOP.MoreAndEqual:
                            return hero.heroData.space >= sc;
                        case Battle.Engine.ConditionOP.Equal:
                            return hero.heroData.space == sc;
                        case Battle.Engine.ConditionOP.LessAndEqual:
                            return hero.heroData.space <= sc;
                        case Battle.Engine.ConditionOP.Less:
                            return hero.heroData.space < sc;
                        default:
                            return false;
                    }
                }
                else
                {
                    Debug.LogError("buff condition error buffer id: " + tb.data.Id + " " + tb.selectStrategy);
                    return false;
                }
            }
        }
        #region 套装
        /// <summary>
        /// 更新套装信息
        /// </summary>
        private void UpdateEquipOutfit()
        {
            activeOutfitEquips.Clear();
            for (int i = 0; i < equipments.Length; i++)
            {
                if (equipments[i] != null)
                {
                    if (!activeOutfitEquips.ContainsKey(equipments[i].equipData.outfitId))
                    {
                        activeOutfitEquips[equipments[i].equipData.outfitId] = 0;
                    }
                    activeOutfitEquips[equipments[i].equipData.outfitId]++;
                }
            }
            currentOutfitAttribute.Reset();
            foreach (var data in activeOutfitEquips)
            {
                List<Dict.DataModel.TableEquipOutfit> outfitData = TableEquipOutfitBlo.GetOutfitAttribute(data.Key, data.Value);
                for (int i = 0; i < outfitData.Count; ++i)
                {
                    currentOutfitAttribute.AddProp(AttributeQueue.Attack, outfitData[i].att);
                    currentOutfitAttribute.AddProp(AttributeQueue.Hp, outfitData[i].hp);
                    currentOutfitAttribute.AddProp(AttributeQueue.PhyDefend, outfitData[i].pdef);
                    currentOutfitAttribute.AddProp(AttributeQueue.MagicDefend, outfitData[i].mdef);
                    currentOutfitAttribute.AddProp(AttributeQueue.cri, outfitData[i].cri);
                    currentOutfitAttribute.AddProp(AttributeQueue.antiCri, outfitData[i].anticri);
                    currentOutfitAttribute.AddProp(AttributeQueue.hit, outfitData[i].perhit);
                    currentOutfitAttribute.AddProp(AttributeQueue.dodge, outfitData[i].perevade);
                    currentOutfitAttribute.AddProp(AttributeQueue.damageAdd, outfitData[i].damadd);
                    currentOutfitAttribute.AddProp(AttributeQueue.damageReduce, outfitData[i].damsub);
                }
            }
        }
        #endregion

        #region 强化大师
        /// <summary>
        /// 得到装备和宝物整体最低等级
        /// </summary>
        /// <param name="minEquipLev"></param>
        /// <param name="minEquipRefinelev"></param>
        /// <param name="minTreaLev"></param>
        /// <param name="minTreaRefineLev"></param>
        public void UpdateStrenthMasterMinLev(out int minEquipLev, out int minEquipRefinelev, out int minTreaLev, out int minTreaRefineLev)
        {
            //得到四件装备中的最低强化等级和最低精炼等级
            //得到两件宝物中的最低强化等级和最低精炼等级
            minEquipLev = int.MaxValue;
            minEquipRefinelev = int.MaxValue;
            minTreaLev = int.MaxValue;
            minTreaRefineLev = int.MaxValue;
            foreach (var data in equipments)
            {
                if (data != null)
                {
                    if (data.level < minEquipLev)
                    {
                        minEquipLev = data.level;
                    }
                    if (data.refineLv < minEquipRefinelev)
                    {
                        minEquipRefinelev = data.refineLv;
                    }
                }
                else
                {
                    minEquipLev = 0;
                    minEquipRefinelev = 0;
                    break;
                }
            }
            foreach (var data in treasures)
            {
                if (data != null)
                {
                    if (data.strengthLevel < minTreaLev)
                    {
                        minTreaLev = data.strengthLevel;
                    }
                    if (data.refineLevel < minTreaRefineLev)
                    {
                        minTreaRefineLev = data.refineLevel;
                    }
                }
                else
                {
                    minTreaLev = 0;
                    minTreaRefineLev = 0;
                    break;
                }
            }
        }



        /// <summary>
        /// 更新强化大师信息
        /// </summary>
        private void UpdateStrenthMaster()
        {
            int minEquipLev = int.MaxValue;
            int minEquipRefinelev = int.MaxValue;
            int minTreaLev = int.MaxValue;
            int minTreaRefineLev = int.MaxValue;
            UpdateStrenthMasterMinLev(out minEquipLev, out minEquipRefinelev, out minTreaLev, out minTreaRefineLev);
            equipStrenthMasterLevData = Dict.Blo.DictStrengthenMasterBlo.GetMeetMasterData(Dict.Config.TableConst.StrenthMasterEquipStrenth, minEquipLev);
            equipRefineMasterLevData = Dict.Blo.DictStrengthenMasterBlo.GetMeetMasterData(Dict.Config.TableConst.StrenthMasterEquipRefine, minEquipRefinelev);
            treaStrenthMasterLevData = Dict.Blo.DictStrengthenMasterBlo.GetMeetMasterData(Dict.Config.TableConst.StrenthMasterTreaStrenth, minTreaLev);
            treaRefineMasterLevData = Dict.Blo.DictStrengthenMasterBlo.GetMeetMasterData(Dict.Config.TableConst.StrenthMasterTreaRefine, minTreaRefineLev);
            partnerMasterLevData = Dict.Blo.DictStrengthenMasterBlo.GetMeetMasterData(Dict.Config.TableConst.StrenthMasterPartner, StaticData.playerData.InstPlayerData.GetPartnerMinLevel());

            List<Dict.DataModel.TableStrengthenMaster> dataList = new List<Dict.DataModel.TableStrengthenMaster>();
            if (equipStrenthMasterLevData != null)
            {
                dataList.Add(equipStrenthMasterLevData);
            }
            if (equipRefineMasterLevData != null)
            {
                dataList.Add(equipRefineMasterLevData);
            }
            if (treaStrenthMasterLevData != null)
            {
                dataList.Add(treaStrenthMasterLevData);
            }
            if (treaRefineMasterLevData != null)
            {
                dataList.Add(treaRefineMasterLevData);
            }
            //伙伴祝福先不上。。
            //if (partnerMasterLevData != null && StaticData.playerData.level >= Dict.DictDataManager.Instance.tableGameConfigureDao.currentData.FriendWishLevel)
            //{
            //    dataList.Add(partnerMasterLevData);
            //}
            this.currentMasterAttribute.Reset();
            foreach (var data in dataList)
            {
                currentMasterAttribute.AddProp(AttributeQueue.Attack, data.att);
                currentMasterAttribute.AddProp(AttributeQueue.Hp, data.hp);
                currentMasterAttribute.AddProp(AttributeQueue.MagicDefend, data.mdef);
                currentMasterAttribute.AddProp(AttributeQueue.PhyDefend, data.pdef);
                currentMasterAttribute.AddProp(AttributeQueue.cri, data.cri);
                currentMasterAttribute.AddProp(AttributeQueue.antiCri, data.anticri);
                currentMasterAttribute.AddProp(AttributeQueue.hit, data.perhit);
                currentMasterAttribute.AddProp(AttributeQueue.dodge, data.perevade);
                currentMasterAttribute.AddProp(AttributeQueue.damageAdd, data.damadd);
                currentMasterAttribute.AddProp(AttributeQueue.damageReduce, data.damsub);
            }
        }

        private void UpdateTitleAttribute()
        {
            this.currentTitleAttribute.Reset();

            if (StaticData.playerData.ownTitleList == null)
                return;

            foreach (var title in StaticData.playerData.ownTitleList)
            {
                TableTitle titledata = DictTitleBlo.GetTableTitle(title);
                foreach (var str in titledata.effects.Split(';'))
                {
                    if (str != "")
                    {
                        string[] propinfo = str.Split(',');
                        int propIndex = BaseAttributeData.GetIndexByDictPropId(propinfo[0]);
                        switch (titledata.type)
                        {
                            case "2":
                                if (hero.heroData.space == 1)
                                {
                                    currentTitleAttribute.AddProp((AttributeQueue)propIndex, float.Parse(propinfo[1]));
                                }
                                break;
                            case "3":
                                if (hero.heroData.space == 2)
                                {
                                    currentTitleAttribute.AddProp((AttributeQueue)propIndex, float.Parse(propinfo[1]));
                                }
                                break;
                            case "4":
                                if (hero.heroData.space == 3)
                                {
                                    currentTitleAttribute.AddProp((AttributeQueue)propIndex, float.Parse(propinfo[1]));
                                }
                                break;
                            default:
                                currentTitleAttribute.AddProp((AttributeQueue)propIndex, float.Parse(propinfo[1]));
                                break;
                        }
                    }
                }
            }
        }

        #endregion

        #region 换实体

        /// <summary>
        /// 切换装备
        /// </summary>
        /// <param name="newguid"></param>
        /// <param name="newPos"></param>
        public void UpdateEquip(string newguid, int newPos)
        {
            if (equipments[newPos - 1] != null)
            {
                equipments[newPos - 1].owner = null;
            }
            equipments[newPos - 1] = simplePlayer.GetUIEquipment(newguid);
            if (equipments[newPos - 1] != null)
            {
                equipments[newPos - 1].owner = this;
                equipments[newPos - 1].lastHeroId = hero.heroId;
                if (newPos == 1)
                {
                    ProtoBuf.Message.CSRefreshMovePlayerInfo csmpi = new ProtoBuf.Message.CSRefreshMovePlayerInfo();
                    NetAPI.SendSocket(ProtoBuf.Message.OpDefine.CSRefreshMovePlayerInfo, csmpi);
                }
            }

            UpdateEquipOutfit();
            UpdateLuck();
            ResetAttribute(simplePlayer.friendBuffers);
        }

        /// <summary>
        /// 切换宝物
        /// </summary>
        /// <param name="newguid"></param>
        /// <param name="newPos"></param>
        public void UpdateTreasure(string newguid, int newPos)
        {
            if (treasures[newPos - 5] != null)
            {
                treasures[newPos - 5].owner = null;
            }
            treasures[newPos - 5] = simplePlayer.GetUITreasure(newguid);
            if (treasures[newPos - 5] != null)
            {
                treasures[newPos - 5].owner = this;
            }
            UpdateLuck();
            ResetAttribute(simplePlayer.friendBuffers);
        }

        /// <summary>
        /// 刷新英雄缘分数据
        /// </summary>
        public void UpdateLuck()
        {
            foreach (var ul in lucks)
            {
                ul.FreshLuckActived();
            }
        }

        #endregion

        #region Tool

        /// <summary>
        /// 获取攻防等属性
        /// </summary>
        /// <param name="prop"></param>
        /// <returns></returns>
        public double GetPorp(AttributeQueue prop)
        {
            return currentAttribute.GetProp(prop);
        }

        public BaseAttributeData CurrentAttribute
        {
            get
            {
                return currentAttribute;
            }
        }

        /// <summary>
        /// 获取战斗力
        /// </summary>
        /// <returns></returns>
        public double GetFightePower()
        {
            return fightPower;
        }
        #endregion


    }
}
